package com.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.entity.Department;
import com.entity.JsonCode;
import com.entity.Person;
import com.service.DepartmentService;
import com.service.PersonService;

public class AddAction extends BaseAction {
	@Autowired
	private PersonService personService;
	@Autowired
	private DepartmentService departmentService;
	List<Department> departments;
	private List<Person> persons;

	public List<Person> getPersons() {
		return persons;
	}

	public void setPersons(List<Person> persons) {
		this.persons = persons;
	}

	public String getStatusCode() {
		return statusCode;
	}

	public void setStatusCode(String statusCode) {
		this.statusCode = statusCode;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getNavTabId() {
		return navTabId;
	}

	public void setNavTabId(String navTabId) {
		this.navTabId = navTabId;
	}

	public String getRel() {
		return rel;
	}

	public void setRel(String rel) {
		this.rel = rel;
	}

	public String getCallbackType() {
		return callbackType;
	}

	public void setCallbackType(String callbackType) {
		this.callbackType = callbackType;
	}

	public String getForwardUrl() {
		return forwardUrl;
	}

	public void setForwardUrl(String forwardUrl) {
		this.forwardUrl = forwardUrl;
	}

	public String getConfirmMsg() {
		return confirmMsg;
	}

	public void setConfirmMsg(String confirmMsg) {
		this.confirmMsg = confirmMsg;
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Person person;
	private Department department;
	private JsonCode json;

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	@Action(value = "add", results = { @Result(type = "json", name = "success") })
	@Override
	public String execute() throws Exception {
		//persons = personService.getAllPersons(new Pagination(), new Person());
		if (person != null) {
			personService.insertPerson(person);
			setOkJson();
			setForwardUrl("show.action?type=p&page.page=1");
		}
		if (department != null) {
			departmentService.insertDepartment(department);
			setOkJson();
			setForwardUrl("show-dep.action?type=d&page.page=1");

		}
		return "success";
	}

	public JsonCode getJson() {
		return json;
	}

	public void setJson(JsonCode json) {
		this.json = json;
	}

}
